package android.meetingatsb

import android.meetingatsb.common.Dating
import android.meetingatsb.common.Requirement
import android.meetingatsb.common.User
import android.meetingatsb.widget.MatchUserCompleteFragment
import android.meetingatsb.widget.RequirementFragment
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ImageView
import android.widget.TextView

class DatingRecordActivity : AppCompatActivity() {
    lateinit var recordDating: Dating
    lateinit var selfRequirement: Requirement
    lateinit var matchRequirement: Requirement
    lateinit var matchUser: User

    val matchUserCompeleteFragment = MatchUserCompleteFragment()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        getData()
        setFragment()
        setContentView(R.layout.activity_dating_record)
        setData()
        setMap()
        setListener()
    }

    private fun getData() {
        recordDating = Dating("yundong", "yumaoqiu", "待评价")
        selfRequirement = Requirement("大学学生",
                "番禺区中环东路华南理工大学",
                "2017/07/19 17:00 - 21:00",
                "暂无")

        matchUser = User("大学生", "大学生", "华南理工大学", 21, "女", 5.0F)
        matchRequirement = Requirement("大学学生",
                "番禺区中环东路华南理工大学",
                "2017/07/19 17:00 - 21:00",
                "暂无")

        val bundle = Bundle()
        bundle.putParcelable("matchUser", matchUser)
        bundle.putParcelable("matchRequirement", matchRequirement)

        matchUserCompeleteFragment.arguments = bundle
    }

    private fun setFragment() {
        val fragTran = fragmentManager.beginTransaction()
        val requirementFragment = RequirementFragment()
        fragTran.replace(R.id.user_requirement_fragment, requirementFragment)
        val bundle = Bundle()
        bundle.putParcelable("requirement", selfRequirement)
        requirementFragment.arguments = bundle
        fragTran.commit()
    }

    private fun setData() {
        (findViewById<TextView>(R.id.dating_type)).text = recordDating.type
        (findViewById<TextView>(R.id.dating_detail)).text = recordDating.detail
        (findViewById<TextView>(R.id.dating_status)).text = recordDating.status
    }

    private fun setMap() {

    }

    private fun setListener() {
        (findViewById<ImageView>(R.id.match_user)).setOnClickListener {

            matchUserCompeleteFragment.show(fragmentManager, "MatchUserInformation")
        }
    }
}